<html>
<head>
    <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>CentOS 7安装和卸载MySql | |ω･`)暗中观察</title>
<meta name="description" content="大爷不进来看看吗？这里有好康的哦~~~" />
<link rel="shortcut icon" href="https://Yanoona.github.io/favicon.ico">
<link rel="stylesheet" href="https://Yanoona.github.io/styles/main.css">

<script src="https://Yanoona.github.io/media/js/jquery.min.js"></script>
<script src="https://Yanoona.github.io/media/js/masonry.pkgd.min.js"></script>
<script src="https://Yanoona.github.io/media/js/aos.js"></script>
<script src="https://Yanoona.github.io/media/js/pace.min.js"></script>
<script src="https://Yanoona.github.io/media/js/view-image.min.js"></script>
<script src="https://Yanoona.github.io/media/js/functions.js"></script>
    <script src="https://Yanoona.github.io/media/js/waterfall.min.js"></script>
    <script src="https://Yanoona.github.io/media/js/prism.min.js"></script>
</head>
<body>
<header id="header" class="grid-container">
    <!-- start: .menu-wrapper -->
    <div class="menu-mobile">
        <i class="fa fa-reorder"></i>
    </div>
    <div class="menu-wrapper">
        <div class="">
            <nav class="main-nav " >
                <ul id="menu-header" class="menu gradient-effect">
                    
                        <li class="">
                            <a href="https://Yanoona.github.io" class="menu">
                                首页
                            </a>
                        </li>
                    
                        <li class="">
                            <a href="https://Yanoona.github.io/archives" class="menu">
                                归档
                            </a>
                        </li>
                    
                        <li class="">
                            <a href="https://Yanoona.github.io/tags" class="menu">
                                标签
                            </a>
                        </li>
                    
                        <li class="">
                            <a href="https://github.com/Yanoona" class="menu">
                                关于
                            </a>
                        </li>
                    
                </ul>
            </nav>
            <!-- end: .main-nav -->
            <div class="clear"></div>
            <div class="border hide-on-tablet hide-on-mobile"></div>
        </div>
        <div class="clear"></div>
    </div>
    <!-- end: .menu-wrapper -->
    <div class="clear"></div>
</header>

<main id="single" class="main grid-container fullcover no-sidebar aos-init aos-animate" data-aos="fade">

    <div class="center content">
        <div class="featured-image cover"
             style="background-image: url('https://Yanoona.github.io/post-images/TeSMMvZK8.jpg');">
            <div class="meta top">
                <time class="meta-info" style="float:left;" datetime="2020-02-19"><i
                            class="fa fa-calendar"></i><span
                            class="lately">4 个月前</span></time>
            </div>
            <div class="info">
                <div class="tags ">
                    
                        <a href="https://Yanoona.github.io/mysql/" class="ctag ctag-0 ctag-mysql"
                           aria-label="">mysql</a>
                    
                        <a href="https://Yanoona.github.io/j_dWapwnj/" class="ctag ctag-1 ctag-j_dWapwnj"
                           aria-label="">CentOS 7</a>
                    
                </div>
                <h1 class="title ularge white bold">CentOS 7安装和卸载MySql</h1>
            </div>
        </div>
    </div>

    <div class="epcl-page-wrapper">
        <div class="left-content grid-70 np-mobile">
            <article class="main-article post">
                <section class="post-content">
                    <div class="text">
                        <h2 id="概述">😀概述</h2>
<p>记录一次CentOS7安装Mysql5.7的步骤和卸载Mysql的步骤。</p>
<h2 id="环境说明">😃环境说明</h2>
<p>机器系统版本：CentOS7.9<br>
所安装Mysql版本：MySql5.7</p>
<!-- more -->
<h2 id="准备安装">😄准备安装</h2>
<p>确保机器上已安装<code>wget</code>,如果没有安装过就使用以下命令进行安装。</p>
<pre><code>yum -y install wget
</code></pre>
<h2 id="开始安装">😁开始安装</h2>
<h3 id="进入官网复制yum源">进入官网复制yum源</h3>
<figure data-type="image" tabindex="1"><img src="https://Yanoona.github.io/post-images/1582081400516.png" alt="" loading="lazy"></figure>
<p>直接点开这个地址并选择第二个（<strong>第一个里面没有MySql5.7版本的下载</strong>）⚡️：<a href="https://dev.mysql.com/downloads/repo/yum/">https://dev.mysql.com/downloads/repo/yum/</a>⚡️</p>
<p>点进去之后，右击超链接文字<strong>No thanks, just start my download.</strong>，再点击<strong>复制链接地址</strong>即可。如下图所示：<br>
<img src="https://Yanoona.github.io/post-images/1582081448581.png" alt="" loading="lazy"></p>
<hr>
<h3 id="下载和安装yum源">下载和安装yum源</h3>
<p>在服务器上运行下载命令👇：</p>
<pre><code>wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
</code></pre>
<p>运行后继续输入以下命令：</p>
<pre><code>rpm -ivh mysql80-community-release-el7-3.noarch.rpm
</code></pre>
<hr>
<h3 id="修改yum源默认安装的版本">修改yum源默认安装的版本</h3>
<p>👴运行查看可安装的mysql的命令：</p>
<pre><code>yum repolist all| grep mysql
</code></pre>
<figure data-type="image" tabindex="2"><img src="https://Yanoona.github.io/post-images/1582081748024.png" alt="" loading="lazy"></figure>
<p>可以看出默认是启用的mysql8.0，5.7是关闭的。</p>
<p>接着运行修改yum配置⚡️（enabled=1 想要安装哪个版本就在哪个版本的后面把0换成1，因为默认是最新版，所以需要把最新版的1换成0，5.7的换为1）⚡️命令：</p>
<pre><code>vim /etc/yum.repos.d/mysql-community.repo
</code></pre>
<figure data-type="image" tabindex="3"><img src="https://Yanoona.github.io/post-images/1582081761005.png" alt="" loading="lazy"></figure>
<p>修改完成后再运行以下命令查看是否已经生效：</p>
<pre><code>yum repolist all| grep mysql
</code></pre>
<figure data-type="image" tabindex="4"><img src="https://Yanoona.github.io/post-images/1582081772383.png" alt="" loading="lazy"></figure>
<p>可以看到配置文件已经生效，接下来使用yum安装MySql。</p>
<hr>
<h3 id="使用yum安装mysql">使用yum安装MySql</h3>
<p>运行安装命令👇：</p>
<pre><code>yum install -y mysql-community-server
</code></pre>
<figure data-type="image" tabindex="5"><img src="https://Yanoona.github.io/post-images/1582081783832.png" alt="" loading="lazy"></figure>
<p><strong>等待安装完成即可！👀</strong></p>
<h2 id="mysql配置">😆MySQL配置</h2>
<h3 id="初始配置">初始配置</h3>
<h4 id="启动mysql服务">🤔启动MySQL服务</h4>
<pre><code>#启动
systemctl start mysqld
#查看状态
systemctl status mysqld
#设置开机自启
systemctl enable mysqld
</code></pre>
<h4 id="查看mysql的初始密码">👀查看MySQL的初始密码</h4>
<blockquote>
<p>初始密码只有在第一次安装或者完全卸载后安装才会有。</p>
</blockquote>
<pre><code>grep 'password' /var/log/mysqld.log
</code></pre>
<figure data-type="image" tabindex="6"><img src="https://Yanoona.github.io/post-images/1582081794593.png" alt="" loading="lazy"></figure>
<p>其中的👉<code>.trj4redlL!</code>👈为初始密码，使用其登录MySQL即可。</p>
<h4 id="修改初始密码">修改初始密码</h4>
<blockquote>
<p>注意：MySQL5.7默认密码策略要求密码⭐️必须是<strong>大小写字母数字特殊字母</strong>的组合⭐️，至少8位</p>
</blockquote>
<pre><code>#修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root123@';
</code></pre>
<h4 id="设置简单密码">设置简单密码</h4>
<p>修改MySQL密码策略，并设置简单密码进行访问🙈🙈。</p>
<pre><code>#查看MySQL密码策略
show variables like 'validate_password%';
#设置全局验证密码策略
set global validate_password_policy=low;
#设置全局验证密码混合情况计数
set global validate_password_mixed_case_count=0;
#设置全局验证密码特殊的字符计数
set global validate_password_special_char_count=0;
#设置全集验证密码长度
set global validate_password_length=4;
</code></pre>
<p>修改密码并赋予用户权限（设置可远程访问🤖）。</p>
<pre><code>#修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';

grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
</code></pre>
<p>刷新权限🙉。</p>
<pre><code>flush privileges;
</code></pre>
<hr>
<h3 id="拓展配置">拓展配置</h3>
<h4 id="修改mysql字符集使其支持中文">修改MySQL字符集，使其支持中文🇨🇳</h4>
<pre><code>#显示字符集变量
show variables like '%character%';
</code></pre>
<figure data-type="image" tabindex="7"><img src="https://Yanoona.github.io/post-images/1582081808778.png" alt="" loading="lazy"></figure>
<p>退出MySQL，编辑MySQL配置文件<strong>my.cnf</strong>，并在文件中添加👇👇行。文件路径在：<code>/etc/my.cnf</code>。</p>
<pre><code>#在[mysqld]中添加
character-set-server=utf8
#在[client]中添加,没有此行请自己添加
default-character-set=utf8
#在[mysql]中添加,没有此行请自己添加
default-character-set=utf8
</code></pre>
<p>保存后，再重启MySQL服务登录MySQL查看👀字符集是否全为utf8。</p>
<figure data-type="image" tabindex="8"><img src="https://Yanoona.github.io/post-images/1582081817742.png" alt="" loading="lazy"></figure>

                    </div>
                    <div class="clear"></div>
                </section>
            </article>
            <div class="clear"></div>

            <section class="related section">
                
                    <article class="prev grid-50 tablet-grid-50 grid-parent">
                        <div class="thumb cover lazy loaded"
                             style="background-image: url('https://Yanoona.github.io/post-images/NNC7-_gM_.jpg');"></div>
                        <a href="https://Yanoona.github.io/NNC7-_gM_/" class="full-link"></a>
                        <div class="info">
                            <time datetime="2020-02-19">2020-02-19</time>
                            <h4 class="title white no-margin">Hadoop到Mysql的数据传输记录</h4>
                        </div>
                        <span class="epcl-button red">
                  <img src="https://Yanoona.github.io/media/images/left-arrow.svg" width="15" alt="Left Arrow">
                </span>
                        <div class="overlay"></div>
                    </article>
                
                
                    <article class="next grid-50 tablet-grid-50 grid-parent">
                        <div class="thumb cover lazy loaded"
                             style="background-image: url('https://Yanoona.github.io/post-images/JD2fNczzi.jpg');"></div>
                        <a href="https://Yanoona.github.io/JD2fNczzi/" class="full-link"></a>
                        <div class="info">
                            <time datetime="2020-02-18">2020-02-18</time>
                            <h4 class="title white no-margin">CentOS 7 中所遇见的异常</h4>
                        </div>
                        <span class="epcl-button red">
                  <img src="https://Yanoona.github.io/media/images/right-arrow.svg" width="15" alt="Left Arrow">
                </span>
                        <div class="overlay"></div>
                    </article>
                

                <div class="clear"></div>
            </section>
        </div>
    </div>
</main>

    <footer id="footer" class="grid-container">
        <div class="widgets row gradient-effect">
            <div class="default-sidebar border-effect">
              <div class="grid-33 tablet-grid-50 mobile-grid-100">
                <section id="tag_cloud-2" class="widget widget_epcl_posts_thumbs underline-effect">
                  <h4 class="widget-title title white bordered">最新文章</h4>
                  
                  
                  <article class="item post-0 post type-post status-publish format-standard has-post-thumbnail hentry">
                    <a href="https://Yanoona.github.io/2rO0MFRF0/" class="thumb hover-effect">
                      <span class="fullimage cover" style="display: block;background-image: url('https://Yanoona.github.io/post-images/2rO0MFRF0.jpg');"></span>
                    </a>
                    <div class="info gradient-effect">
                      <time datetime="2020-06-29">2020-06-29</time>
                      <h4 class="title usmall">
                        <a href="https://Yanoona.github.io/2rO0MFRF0/">Java8 Stream流学习笔记</a>
                      </h4>
                    </div>
                    <div class="clear"></div>
                  </article>
                  
                  
                  
                  <article class="item post-1 post type-post status-publish format-standard has-post-thumbnail hentry">
                    <a href="https://Yanoona.github.io/ta0wVkBzF/" class="thumb hover-effect">
                      <span class="fullimage cover" style="display: block;background-image: url('https://Yanoona.github.io/post-images/ta0wVkBzF.jpg');"></span>
                    </a>
                    <div class="info gradient-effect">
                      <time datetime="2020-05-13">2020-05-13</time>
                      <h4 class="title usmall">
                        <a href="https://Yanoona.github.io/ta0wVkBzF/">Spring 知识回顾之 体系结构</a>
                      </h4>
                    </div>
                    <div class="clear"></div>
                  </article>
                  
                  
                  
                  <article class="item post-2 post type-post status-publish format-standard has-post-thumbnail hentry">
                    <a href="https://Yanoona.github.io/CpjS5YWXn/" class="thumb hover-effect">
                      <span class="fullimage cover" style="display: block;background-image: url('https://Yanoona.github.io/post-images/CpjS5YWXn.jpg');"></span>
                    </a>
                    <div class="info gradient-effect">
                      <time datetime="2020-05-13">2020-05-13</time>
                      <h4 class="title usmall">
                        <a href="https://Yanoona.github.io/CpjS5YWXn/">Spring 知识回顾之 概念</a>
                      </h4>
                    </div>
                    <div class="clear"></div>
                  </article>
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  <div class="clear"></div>
                </section>
              </div>

              <div class="grid-33 tablet-grid-50 mobile-grid-100">
                <section id="tag_cloud-2" class="widget widget_tag_cloud underline-effect">
                  <h4 class="widget-title title white bordered">标签云</h4>
                  <div class="tagcloud">
                    
                      <a href="https://Yanoona.github.io/java/" class="ctag ctag-0 ctag-java" aria-label="">Java</a>
                    
                      <a href="https://Yanoona.github.io/7D-9V5P5T/" class="ctag ctag-1 ctag-7D-9V5P5T" aria-label="">Spring</a>
                    
                      <a href="https://Yanoona.github.io/wDtcCNomO/" class="ctag ctag-2 ctag-wDtcCNomO" aria-label="">Crontab定时任务</a>
                    
                      <a href="https://Yanoona.github.io/j_dWapwnj/" class="ctag ctag-3 ctag-j_dWapwnj" aria-label="">CentOS 7</a>
                    
                      <a href="https://Yanoona.github.io/dXBZlTYs0/" class="ctag ctag-4 ctag-dXBZlTYs0" aria-label="">Vue</a>
                    
                      <a href="https://Yanoona.github.io/bigData/" class="ctag ctag-5 ctag-bigData" aria-label="">大数据</a>
                    
                      <a href="https://Yanoona.github.io/Sqoop/" class="ctag ctag-6 ctag-Sqoop" aria-label="">Sqoop</a>
                    
                      <a href="https://Yanoona.github.io/Hive/" class="ctag ctag-7 ctag-Hive" aria-label="">Hive</a>
                    
                      <a href="https://Yanoona.github.io/mysql/" class="ctag ctag-8 ctag-mysql" aria-label="">mysql</a>
                    
                      <a href="https://Yanoona.github.io/Hadoop/" class="ctag ctag-9 ctag-Hadoop" aria-label="">Hadoop</a>
                    
                  </div>
                  <div class="clear"></div>
                </section>
              </div>

              <div class="grid-33 tablet-grid-50 mobile-grid-100">
                <section id="epcl_about-2" class="widget widget_epcl_about underline-effect">
                  <h4 class="widget-title title white bordered">关于我</h4>
                  <div class="avatar">
                    <a href="https://github.com/Yanoona" class="translate-effect thumb"><span class="fullimage cover" style="background-image: url(https://Yanoona.github.io/images/avatar.png);"></span></a>
                  </div>
                  <div class="info">
                    <h4 class="title small author-name gradient-effect no-margin"><a href="https://github.com/Yanoona">|ω･`)暗中观察</a></h4>
                    <p class="founder">大爷不进来看看吗？这里有好康的哦~~~</p>
                    <div class="social">
                      
                        
                            <a href="https://github.com/Yanoona" class="translate-effect" target="_blank"><i class="fa fa-github"></i></a>
                        
                      
                        
                      
                        
                            <a href="https://blog.csdn.net/qq_39299449" class="translate-effect" target="_blank"><i class="fa fa-csdn"></i></a>
                        
                      
                        
                            <a href="https://www.jianshu.com/u/6d8fc7359702" class="translate-effect" target="_blank"><i class="fa fa-jianshu"></i></a>
                        
                      
                    </div>
                  </div>
                  <div class="clear"></div>
                  </section>
              </div>

            </div>
            <div class="clear"></div>
        </div>

        <p class="published border-effect">
          ©2020 共 12 篇文章
        </p>
        
        <a href="javascript:void(0)" id="back-to-top" class="epcl-button dark" style="display:none">
          <i class="fa fa-arrow"></i>
        </a>
    </footer>
    <div class="clear"></div>

<script type="text/javascript">
    jQuery(document).ready(function ($) {
        $("photos img").each(function () {
            var _a = $("<a></a>").attr("href", this.src);
            $(this).wrap("<div class='photo'></div>").wrap(_a);
        })
        $("figure img").each(function () {
            var _b = $("<a></a>").attr("href", this.src);
            $(this).wrap(_b);
        })
        isImgLoad(function () {
            var photos = document.querySelector('photos');
            if (photos) {
                waterfall(photos);
            }
            $(window).resize(function () {
                if (photos) {
                    waterfall(photos);
                }
            });
        });
        var t_img;
        var isLoad = true;

        function isImgLoad(callback) {
            $('photos img').each(function () {
                if (this.height === 0) {
                    isLoad = false;
                    return false;
                }
            });
            if (isLoad) {
                clearTimeout(t_img);
                callback();
            } else {
                isLoad = true;
                t_img = setTimeout(function () {
                    isImgLoad(callback);
                }, 500);
            }
        }
    });
</script>

</div>
<!-- end: #wrapper -->
</body>
</html>
